<div class="modal-body pageContent">
     <div class="row">
          <div class="col-lg-12 col-lg-offset-2">
               <div class="upload">
                    <form action="/rework/reworkFile" enctype="multipart/form-data" method='post' id="form1">
                         <div class="form-group">
                              <label class="col-lg-12 control-label">返修单号</label>
                              <div class="col-lg-12">
                                  <input type="text" class="form-control" name="name" value="" />
                              </div>
                         </div>
                         <div class="form-group">
                              <label class="col-lg-12 control-label">附件</label>
                              <div class="col-lg-12">
                                  <input type="file" name="file" accept=".xls,.xlsx"/>
                              </div>
                         </div>
                    </form>
               </div>
          </div>
     </div>
</div>
<div class="modal-footer pageFooter">
    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
     <button  class="btn btn-primary"  type="submit" >保存</button>  
</div>

<script type="text/javascript">
 $(document).ready(function() {  
       $('.selectpicker').selectpicker();//初始化
       $('#form1').bootstrapValidator({
            message: '此值无效',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                name: {
                    validators: {
                        notEmpty: {
                            message: '请填写返修单号'
                        },
                    }
                },
                file: {
                    validators: {
                        notEmpty: {
                            message: '上传文件不能为空'
                        }
                        // file: {
                        //     extension: 'png,jpg,jpeg',
                        //     type: 'image/png,image/jpg,image/jpeg',
                        //     message: '请重新选择图片'
                        // }
                    }
                }
            }
        })
        .on('success.form.bv', function(e) {
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            // var formData = new FormData($form[0]);
            // $.post($form.attr('action'), $form.serialize(), function(result) {
            //    debugger
            //     if(result.statusCode =='200'){
            //          toastr.success(result.message+'!');
            //           $('#reworkPage').modal('hide');
            //           $("#productTable").bootstrapTable('refresh');
            //     }else{
            //         toastr.warning(result.message+'!');
            //            $('#reworkPage').modal('hide');
            //            $("#productTable").bootstrapTable('refresh');
            //     }               
            // }, 'json');
           var formData = new FormData($("#form1")[0]); //换成上面这种表单数据绿色提交，file格式识别不到 
             $.ajax({  
                  url: '/rework/reworkFile' ,  
                  type: 'POST',  
                  data: formData,  
                  async: false,  
                  cache: false,  
                  contentType: false,  
                  processData: false,  
                  success: function (returndata) { 
                    if(returndata.length===9371){   //session超时返回的登录页面 避免接口返回的也是字符串不是json
                                location.href="/severError";
                    }else{  //正常处理
                         if(JSON.parse(returndata).statusCode==200){
                              toastr.success(JSON.parse(returndata).message+'!');
                              $('#reworkPage').modal('hide');
                              $("#productTable").bootstrapTable('refresh');
                         }else{                 //报300不关闭当前窗口
                              toastr.warning(JSON.parse(returndata).message+'!');
                              // $('#reworkPage').modal('hide');
                              // $("#productTable").bootstrapTable('refresh');
                         }
                    }
                  },  
                  error: function (returndata) {  
                    toastr.error(JSON.parse(returndata).message+'!');
                         $('#reworkPage').modal('hide');

                    $("#productTable").bootstrapTable('refresh');
                  }  
             });  
        });
       }) 
</script>